package openapi_remote

import (
	"context"
	"errors"
	"git.mycaigou.com/gfyx/common/http_client"
	"strings"
)

type openApiRepo struct{}

func NewCompanyRepo() OpenApiRepoIface {
	return &openApiRepo{}
}

func (c *openApiRepo) GetCompanyDetail(ctx context.Context, keyword string) (*CompanyDetailBo, error) {
	resp := &CompanyDetailBo{}
	keyword = strings.TrimSpace(keyword)
	if keyword == "" {
		return resp, nil
	}
	path := "/v1/company/detail-info"
	openapiClient := http_client.NewOpenApiHttpClient()
	params := map[string]interface{}{
		"keyword": keyword,
	}
	result := &CompanyDetailResponseBo{}
	_, _, errs := openapiClient.Get(ctx, path, params, nil).EndStruct(result)
	if len(errs) > 0 {
		return resp, errs[0]
	}
	if result.Success == false {
		err := errors.New("获取企业信息失败：" + result.Message)
		return resp, err
	}

	return &result.Data, nil
}
